package com.wk1un2.web.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.wk1un2.entity.User;
import com.wk1un2.service.UserService;

@Controller
public class StaticWebController {

	@Autowired
	UserService UserService;

	@RequestMapping("/getStatic")
	public String getStatic(Model model, HttpSession session) {
		Integer u_id = ((User) session.getAttribute("USER_SESSION")).getU_id();
		if (u_id != null) {
			List<Map<String, Object>> getUser = UserService.getStatic(u_id);
			model.addAttribute("getUser", getUser);
			return "Static_User";
		}
		return "forward:login.jsp";
	}

	@RequestMapping("/getStaticSafe")
	public String getStaticSafe(Model model, HttpSession session) {
		Integer u_id = ((User) session.getAttribute("USER_SESSION")).getU_id();
		if (u_id != null) {
			List<Map<String, Object>> getUser = UserService.getStatic(u_id);
			model.addAttribute("getUser", getUser);
			return "Static_Safe";
		}
		return "forward:login.jsp";
	}

	@RequestMapping("/UpdateStaticSafe")
	public String UpdateStaticSafe(Model model, HttpSession session, @RequestParam Map<String, Object> map) {
		User u = (User) session.getAttribute("USER_SESSION");
		map.put("u_id", u.getU_id());
		UserService.UpdateSafe(map);
		return "redirect:getStaticSafe";
	}
}
